#include<iostream>
#include<set>
using namespace std;

struct vip{
	int id;
	int shi;
}; 

struct rule1{
	bool operator()(const vip &a1,const vip &a2){
		return a1.shi<a2.shi;
	}
};

int main(){
	multiset <vip,rule1> v;
	int n;
	vip s;
	cin>>n;
	s.id=1;s.shi=1000000000;
	v.insert(s);
	multiset<vip,rule1>::iterator p;
	multiset<vip,rule1>::iterator p1;
	multiset<vip,rule1>::iterator p2;
	multiset<vip,rule1>::iterator p0;
	vip t[n];
	for( int i=0; i<n; i++ ){
		cin>>t[i].id>>t[i].shi;
	}
	for( int i=0; i<n; i++ ){
		s.id=t[i].id;s.shi=t[i].shi;
		v.insert(s);
		p0=p=v.find(s);
			p1=++p;
			p=p0;
			p2=--p;
			p=p0;
		if( p==v.begin() ){
			cout<<p->id<<" "<<p1->id; 
		}else if( p==v.end() ){
			cout<<p->id<<" "<<p2->id;
		}else if( (p1->shi-p->shi)<(p->shi-p2->shi) ){
			cout<<p->id<<" "<<p1->id; 
		}else{
			cout<<p->id<<" "<<p2->id; 
		} 	 
		if (i!=n-1)
		cout<<endl;
	} 
	return 0;
}
